import configparser
from configparser import ConfigParser

file_path = 'user.ini'
conf = configparser.ConfigParser()


def checkUser(account):  # 通过account查询用户信息
    conf.read('user.ini')
    if not conf.has_section('user'):
        return None
    try:
        return conf.get('user', account)
    except Exception:
        return None


def insertUser(account, password, nickname):  # 插入用户信息
    conf.read('user.ini')
    if not conf.has_section('user'):
        conf.add_section('user')
    conf.set('user', account, password + ',' + nickname)
    conf.write(open(file_path, 'w'))


if __name__ == '__main__':
    conf.read('user.ini')
    # conf.add_section('user')
    # conf.set('user', 'admin', '123')
    # conf.set('user', 'admin', '123')
    # conf.set('user', 'dasd', '123')
    conf.set('user', 'dasfasdasdasd', '123')
    conf.write(open(file_path, 'w'))
